/*************************************************************************
	> File Name: 2.0-1背包.cpp
	> Author: 
	> Mail: 
	> Created Time: 
 ************************************************************************/
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, bag;
    vector<int> w, v;
    cin >> n >> bag;
    for (int i = 0, x; i < n; i++) {
        cin >> x;
        w.push_back(x);
    }
    for (int i = 0, x; i < n; i++) {
        cin >> x;
        v.push_back(x);
    }
    vector<vector<int> > dp(n + 1, vector<int>(bag + 1, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= bag; j++) {
            if (j - w[i - 1] >= 0) {
                dp[i][j] = max(dp[i - 1][j - w[i - 1]] + v[i - 1], dp[i - 1][j]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    cout << dp[n][bag] << endl;
    return 0;
}
